package com.yx.test;

import com.baidu.aip.ocr.AipOcr;
import com.yx.config.BaiduConfig;
import org.json.JSONObject;

import java.util.HashMap;

public class Demo {
    public static void main(String[] args) {
        IDCardRecogize();
    }

    public static void IDCardRecogize() {
        AipOcr client = new AipOcr(BaiduConfig.APP_ID, BaiduConfig.API_KEY, BaiduConfig.SECRET_KEY);
        // 传入可选参数调用接口
        HashMap<String, String> options = new HashMap<String, String>();
        options.put("detect_direction", "true");
        options.put("detect_risk", "false");
        //背面照
        //String idCardSide = "back";

        //前面照
        String idCardSide = "front";

        // 参数为本地图片路径
        //String image = "D:\\back.jpg";
        //String image = "D:\\front.jpg";
        String image = "D:\\zhuomian\\photo\\22.jpg";//身份证照片路径
        JSONObject res = client.idcard(image, idCardSide, options);
        System.out.println(res.toString(2));

        // 参数为本地图片二进制数组
       /* byte[] file = Utils.readImageFile(image);
        res = client.idcard(file, idCardSide, options);
        System.out.println(res.toString(2));*/

    }
}
